#pragma once
#include "Vec2.hpp"

class TriIntersect
{
public:
   
   TriIntersect();
   void Segment(const Vec2& a, const Vec2& b, const Vec2& c,
                const Vec2& p1, const Vec2& p2);


   enum ResultType
   {
      cNONE,
      cPOINT,
      cLINE_POINT,
      cLINE_LINE
   };
   
   ResultType GetResult() const { return mResult.mResultType; }

   void GetIntersections(Vec2& aP1, Vec2& aP2) const
   {
      aP1 = mResult.mP1;
      aP2 = mResult.mP2;
   }
   
   void GetHits(int aHits[2]) const { aHits[0] = mResult.mHitEdges[0]; aHits[1] = mResult.mHitEdges[1]; }

   void Find();

private:

   int GetInterval(float aDist[3],
                   int   aSign[3],
                   float aParam[2],
                   int   aEdges[2]);

   struct Query
   {
      Vec2 v[3];
      Vec2 p;
      Vec2 d;
   };
   struct Result
   {
      ResultType  mResultType;
      Vec2        mP1;
      Vec2        mP2;
      int         mHitEdges[2];
   };
   void Relate(float aDist[3],
               int   aSign[3],
               int&  aPos,
               int&  aNeg,
               int&  aZero);

   Query   mQuery;
   Result  mResult;
};
